$(function () {


    function tpllist(list) {

        var str = '';
        for (var i = 0; i < list.length; i++) {
            str += '<tr data-id="' + list[i].id + '" >' +
                '<td>' + list[i]['日期'] + '</td>' +
                '<td>' + list[i]['用户姓名'] + '</td>' +
                '<td>' + list[i]['归属房间'] + '</td>' +
                '<td>' + list[i]['直属上限'] + '</td>' +
                '<td>' + list[i]['今日上分'] + '</td>' +
                '<td>' + list[i]['今日赢分'] + '</td>' +
                '<td>' + list[i]['获利'] + '</td>' +
                '</tr>'
        }

        return str
    }

    $('.export1').click(function () {
        var token = window.localStorage.getItem('token');
        var startTime = $("#time-start").val() || "";
        var endTime = $("#time-end").val() || "";
        $('#dividend-print2').attr("action", "/deal/doExportUserDataInfo?token=" + token + "&startTime=" + startTime + "&endTime=" + endTime);
        $('#dividend-print2').submit();
    });



    function pageInit(requestData) {
        // console.log(requestData)
        var pageInit_layer = layer.load(0);
        $.restPost('/deal/doQueryUserDataInfo', requestData).done(function (msg, data) {

            layer.close(pageInit_layer)


            $("#data-table tbody").html(tpllist(data.list))



        }).fail(function (msg) {
            layer.close(pageInit_layer)
            $.rootErrorDialog(msg, 2000)
        })
    }

    var preData = (new Date(new Date() - 24 * 60 * 60 * 1000)).format("yyyy-MM-dd")
    function getTableData($dom1, $dom2,preData, callback) {
        $dom1.val(preData).datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            autoclose: 1,
            minView: "3"
        });
        $dom2.val(preData).datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            autoclose: 1,
            minView: "3"
        });
        callback($dom1.val(), $dom2.val())
        $dom1.off("change").on("change", function () {

            callback($dom1.val(), $dom2.val())
        })

        $dom2.off("change").on("change", function () {

            callback($dom1.val(), $dom2.val())
        })


    }


    getTableData($("#time-start"),$("#time-end"),preData,function (t1,t2) {
        pageInit({
            pageNum: 1,
            pageSize: 10,
            token: window.localStorage.getItem('token'),
            startTime:t1,
            endTime:t2
        });
    })
});
